<?php

class Core_Model_Promotion_Collection_Ad extends Dcmp_Model_Collection_Strong {

    public function __construct() {
        parent::__construct();
        $this->setItemClass('promotion/ad');
        $this->from('{t}promotion_ad', 'a')->select()->field('a.*');
    }

    public function filterBy($name, $arg) {
        switch ($name){
            case 'id':
                $this->addParameter(array('id'=>$arg))->contain('a.id',':id:i');
                break;
            case 'status':
                $this->addParameter('status',$arg)->eq('status',':status:s');
                break;
            case 'position':
                $this->addParameter('position', $arg)->eq('position',':position:s');
                break;
            case 'time':
                $this->addParameter(array('start_time'=>$arg,'end_time'=>$arg))->lteq('start_time',':start_time:s')->gt('end_time',':end_time:s');
                break;
        }
        return $this;
    }

    public function joinPosition(){
        $this->innerJoin('{t}promotion_position', 'b', 'a.position', 'b.code')
                ->field('b.name', 'position_name')
                ->field('b.width', 'width')
                ->field('b.height', 'height');
        return $this;
    }
}

